package cj.web.marry.dao;
/*
 *  
 *  
*/
import java.util.List;
import java.util.Map;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;

/**
 * 
 * @author 
 *
 */
@DAO
public interface PubActDAO{
	
	@SQL("SELECT id,img,type,name,startDate,endDate,price,duration FROM PubActivity WHERE deleteFlag=1 AND startDate <= now() AND endDate > now() ORDER BY orderNo DESC,endDate DESC ")
    List<Map> queryAllForEndDate();
	
	@SQL("SELECT id,img,type,name,startDate,endDate,price,duration FROM PubActivity WHERE deleteFlag=1 AND startDate <= now() AND endDate > now() ORDER BY orderNo DESC,endDate DESC LIMIT :1,:2")
    List<Map> queryAllForEndDate(int start,int length);
	
	@SQL("SELECT count(1) FROM PubActivity WHERE deleteFlag=1 AND startDate <= now() AND endDate > now() ")
    int queryAllForEndDateSize();
		
	@SQL("SELECT * FROM PubActivity WHERE id=:1 ")
    List<Map> queryById(int id);
	
	@SQL("SELECT * FROM PubActivityOrder WHERE orderNo=:1 ")
    List<Map> queryActOrdById(String orderNo);
	
	@SQL("INSERT INTO PubActivityOrder ("
    		+ "pubActivityId,"
    		+ "orderNo,"
    		+ "userId,"
    		+ "duration,"
    		+ "price,"
    		+ "status,"
    		+ "deleteFlag,"
    		+ "createAt,"
    		+ "createUser,"
    		+ "updateAt,"
    		+ "updateUser"
			+") VALUES ("
			+ ":1,"
			+ ":2,"
			+ ":3,"
			+ ":4,"
			+ ":5,"
			+ "2,"
			+ "1,"
			+ "now(),"
			+ ":6,"
			+ "now(),"
			+ ":6)")
	void createPubActOrder(int pubActivityId,String orderNo,int userId,String duration,String price,String phone);
	
	@SQL("SELECT count(1) FROM PubActivityOrder WHERE deleteFlag=1 AND userId=:1 AND pubActivityId=:2 ")
    int queryPubActivityOrderCount(int userId,int pubActivityId);
	
	@SQL("SELECT a.*,b.name as pubActivityName,b.img FROM PubActivityOrder a join PubActivity b on a.pubActivityId=b.id WHERE a.deleteFlag=1 AND a.userId=:1 ORDER BY a.updateAt DESC LIMIT :2,:3 ")
    List<Map> queryPubActivityOrder(int userId,int start,int length);
	
	@SQL("SELECT count(1) FROM PubActivityOrder WHERE deleteFlag=1 AND userId=:1 ")
    int queryPubActivityOrderCount(int userId);
	
	@SQL("SELECT userId FROM PubActivityOrder WHERE pubActivityId=:1 ")
    List<Integer> queryPubActivityOrderByActId(int pubActivityId);
	
	@SQL("SELECT * FROM PubActivityOrder WHERE id=:1 ")
    List<Map> queryPubActivityOrderById(int id);
	
	@SQL("update PubActivity set count=count+1 where id=:1")
	void updatePubActivity(int id);
	
	@SQL("update PubActivity set status=:2,payOrder=:3,payWay=:4,source=:5 where orderNo=:1")
	void updatePubActivity(String orderNo,int status,String payOrder,int payWay,int source);
}